import java.util.*;

public class Solution {
    public int threeSumClosest(int[] nums, int target) {
        Arrays.sort(nums);
        int ans = Integer.MAX_VALUE;
        int cha = Integer.MAX_VALUE;
        for(int i = 0; i < nums.length; i++){
            int sum = target - nums[i];
            int l = i + 1;
            int r = nums.length - 1;
            while(l < r){
                int tmp = nums[l] + nums[r];
                if(Math.abs(sum - tmp) < cha){
                    cha = Math.abs(sum - tmp);
                    ans = tmp - sum + target;
                }
                if(tmp > sum) {
                    r--;
                }else{
                    l++;
                }
            }
        }
        return ans;
    }

    public List<List<Integer>> threeSum(int[] nums) {
        return new ArrayList<>();
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        solution.threeSumClosest(new int[]{0,1,1,1}, -100);
    }
}
